package cs.rsa.ts14.framework;

/**
 * Created by michaelbirkholm on 22/02/14.
 */
public class StandardLineTypeClassifierStrategy implements LineTypeClassifierStrategy {
    @Override
    public LineType classify(String line) {

        System.out.println("line " + line);

        String weekPattern = "Week\\s+[0-9]+\\s+:\\s+[0-5]\\s+:\\s+[0-5]\\s*";
        String assignmentPattern = "\\w+\\s+=+\\s+[0-9]+(.[0-9])?";
        String weekdayPattern = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\\s+(Bi|Ca|Pu|Tr|No|Ho)\\s+.+";
        String workSpecificationPattern = "\\s+[a-zA-Z]\\w*\\s+(-|[a-zA-Z]\\w*)\\s+\\d+(.0|.5)?";
        String emptyLinePattern = "^\\s+$";
        String commentLinePattern = "#.*";

        if (line.matches(assignmentPattern))    {
            return LineType.ASSIGNMENT_LINE;
        } else if (line.matches(weekPattern)){
            return LineType.WEEK_SPECIFICATION;
        } else if (line.matches(weekdayPattern)){
            return LineType.WEEKDAY_SPECIFICATION;
        } else if (line.matches(workSpecificationPattern)){
            return LineType.WORK_SPECIFICATION;
        } else if (line.matches(emptyLinePattern)){
            return LineType.EMPTY_LINE;
        } else if (line.matches(commentLinePattern)) {
            return LineType.COMMENT_LINE;
        } else {
            return LineType.INVALID_LINE;
        }
    }

    @Override
    public String lastError() {
        return null;
    }
}
